home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_type1.ps < prev    next >
Text File  |  2003-01-03  |  6KB  |  173 lines

  1. %    Copyright (C) 1994, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Type 1 font support code.
  7.  
  8. % The standard representation for PostScript compatible fonts is described
  9. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  10.  
  11. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  12. % and UnderlineThickness entries in FontInfo if they aren't there already,
  13. % and FontBBox isn't degenerate.
  14. % (This works around the incorrect assumption, made by many word processors,
  15. % that these entries are present in the built-in fonts.)
  16. /.buildfont1
  17.  {
  18.    false 1 index /FontBBox .knownget {
  19.      { 0 ne { not exit } if } forall
  20.    } if
  21.    { dup /FontInfo known not
  22.       { .growfontdict dup /FontInfo 2 dict put }
  23.      if
  24.      dup dup /FontInfo get dup dup
  25.      /UnderlinePosition known exch /UnderlineThickness known and
  26.       { pop pop        % entries already present
  27.       }
  28.       { dup length 2 add dict .copydict
  29.         dup /UnderlinePosition known not
  30.          { dup /UnderlinePosition 3 index /FontBBox .knownget
  31.             { 1 get 2 div }            % 1/2 the font descent
  32.         { -100 } ifelse put
  33.          }
  34.         if
  35.         dup /UnderlineThickness known not
  36.          { dup /UnderlineThickness 3 index /FontBBox .knownget
  37.             { dup 3 get exch 1 get sub 20 div }    % 1/20 the font height
  38.             { 50 } ifelse put
  39.          }
  40.         if
  41.         1 index /FontInfo get wcheck not { readonly } if
  42.         /FontInfo exch put
  43.       }
  44.      ifelse
  45.    } if
  46.    //.buildfont1
  47.  } bind def
  48. % If the diskfont feature isn't included, define a dummy .loadfontdict.
  49. /.loadfontdict where
  50.  { pop }
  51.  { /.loadfontdict 0 dict readonly def }
  52. ifelse
  53. /.loadfontfile        % <file> .loadfontfile -
  54.  { mark exch
  55.    DISKFONTS { .loadfontdict begin } if
  56.     % In order to load fonts reliably, we should push systemdict
  57.     % here.  However, Ed Taft says that Adobe implementations
  58.     % push userdict and nothing else!
  59.     % We really would just like systemdict on the stack,
  60.     % but fonts produced by Fontographer require a writable dictionary.
  61.     % However, we can't use any of the other well-known dictionaries
  62.     % (such as userdict), since the whole point of pushing systemdict
  63.     % is to make sure that nothing important has been redefined.
  64.    userdict begin
  65.     % We can't just use `run', because we want to check for .PFB files.
  66.    currentpacking
  67.     { false setpacking .loadfont1 true setpacking }
  68.     { .loadfont1 }
  69.    ifelse end
  70.     { stop } if
  71.    DISKFONTS { end } if
  72.    cleartomark
  73.  } bind def
  74. /.loadfont1 {        % <file> .loadfont1 <errorflag>
  75.   {    % We would like to use `false /PFBDecode filter',
  76.     % but this occasionally produces a whitespace character as
  77.     % the first of an eexec section, so we can't do it.
  78.     % Also, since the real input file never reaches EOF if we are using
  79.     % a PFBDecode filter (the filter stops just after reading the last
  80.     % character), we must explicitly close the real file in this case.
  81.     % Since the file might leave garbage on the operand stack,
  82.     % we have to create a procedure to close the file reliably.
  83.     dup read not { -1 } if
  84.     2 copy unread 16#80 eq {
  85.     dup true /PFBDecode filter cvx
  86.     exch .currentresourcefile eq {
  87.       dup /.execasresource .systemvar
  88.     } {
  89.       {exec}
  90.     } ifelse
  91.     2 index cvlit
  92.     /closefile .systemvar 3 .execn
  93.       } {
  94.     cvx exec
  95.     } ifelse
  96.   } stopped
  97. } bind def
  98.  
  99. % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
  100. % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
  101. % The real work is done in an operator:
  102. %    <font> <code|name> <name> <charstring> .type1execchar -
  103.  
  104. (%Type1BuildChar)  cvn {    % <font> <code> %Type1BuildChar -
  105.   1 index /Encoding get 1 index get .type1build .type1execchar
  106. } bind def
  107. (%Type1BuildGlyph) cvn {    % <font> <name> %Type1BuildGlyph -
  108.   dup .type1build .type1execchar
  109. } bind def
  110. % Note: this procedure is used for both Type 1 and Type 2 fonts.
  111. /.type1build {        % <font> <code|name> <name> .type1build
  112.             %   <font> <code|name> <name> <charstring>
  113.   2 index begin
  114.     dup CharStrings exch .knownget not {
  115.       2 copy eq { exch pop /.notdef exch } if
  116.        QUIET not
  117.     { (Substituting .notdef for ) print = flush }
  118.     { pop }
  119.        ifelse
  120.        /.notdef CharStrings /.notdef get
  121.     } if
  122.   end
  123. } bind def
  124. % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
  125. 1183615869 internaldict begin
  126. % Apparently there are two different argument lists for CCRun.
  127. % Handling the one with the extra Private dictionary requires fabricating
  128. % a Type 1 font on the fly, since we aren't currently prepared to parse the
  129. % dictionary any other way.
  130. /CCRun {    % <font> <code|name> <charstring> CCRun -
  131.         % <font> <code|name> <charstring> <Private> CCRun -
  132.   dup type /dicttype eq {
  133.     dup 4 index /Private .knownget { ne } { pop true } ifelse {
  134.         % The Private dictionary was supplied, and is different
  135.         % from the Private dictionary of the font.  Fabricate a
  136.         % Type 1 font with this Private dictionary.  Most of the
  137.         % font entries are arbitrary or not needed.
  138.       .currentglobal false .setglobal 10 dict exch .setglobal begin
  139.     /Private exch def
  140.     /FontType 1 def
  141.     /FontMatrix 3 index /FontMatrix get def
  142.     /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
  143.     /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
  144.     /PaintType 0 def
  145.     /CharStrings 1 dict dup /.notdef () put def
  146.       3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
  147.     } {
  148.       pop
  149.     } ifelse
  150.   } if
  151.   1 index dup type /integertype eq {
  152.     3 index /Encoding get exch get
  153.   } if exch .type1execchar
  154. } bind def
  155. end
  156.  
  157. % Register the font types for definefont.
  158. buildfontdict 1 /.buildfont1 cvx put
  159. buildfontdict 4 /.buildfont4 cvx put
  160.  
  161. % Add Type 2 support if applicable.
  162. /.buildfont2 where not { (%END2) .skipeof } if
  163. pop
  164. (%Type2BuildChar)  cvn {    % <font> <code> %Type2BuildChar -
  165.   1 index /Encoding get 1 index get .type1build .type2execchar
  166. } bind def
  167. (%Type2BuildGlyph) cvn {    % <font> <name> %Type2BuildGlyph -
  168.   dup .type1build .type2execchar
  169. } bind def
  170. buildfontdict 2 /.buildfont2 cvx put
  171. %END2
  172.